package com.groupfive.service.impl;

import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.groupfive.mapper.ArticleMapper;
import com.groupfive.pojo.Article;
import com.groupfive.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public int add(Article article) {
        article.setTime(DateUtil.now());
        return articleMapper.insert(article);
    }

    @Override
    public int update(Article article) {
        return articleMapper.update(article);
    }

    @Override
    public int deleteById(Long id) {
        return articleMapper.deleteById(id);
    }

    @Override
    public void deleteBatch(List<Long> ids) {
        for (Long id : ids){
            articleMapper.deleteById(id);
        }
    }

    @Override
    public List<Article> selectAll(Article article) {
        return articleMapper.selectAll(article);
    }

    @Override
    public Article selectById(Long id) {
        return articleMapper.selectById(id);
    }

    @Override
    public PageInfo<Article> selectPage(Article article, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Article> list = articleMapper.selectAll(article);
        return PageInfo.of(list);
    }

}
